package com.adxon.cookie;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

import com.adxon.data.ItemEx;
import com.adxon.data.User;

public class Badge extends Kooky{
	private static String ATR="e";

	public static Badge get(HttpServletRequest req){
		getAll(req);
		return (Badge)req.getAttribute(ATR);	
	}

	private ItemEx own;

	public Badge(){
		atr=idx=ATR;
	}
	public User getOwner(){
		return (User)own;
	}
	public void setOwner(User owner){
		own=owner;
		if(owner==null){
			cki=new Cookie(idx,null);
			cki.setPath("/");
			cki.setMaxAge(0);
		}else{
			String x=owner.getText();
			if(x==null)
				x="";
			cki=new Cookie(idx,owner.getId()+"*"+owner.getPermaLink()+'*'+
					owner.getAttachmentId()+'*'+x+'*'+owner.getRate());
			cki.setPath("/");
			cki.setMaxAge(3600*24*3652);
		}
	}
}